﻿using System;
using OpenVision.Models;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace OpenVision.Data
{
    public class OpenVisionContext : DbContext
    {
        private const string CONNECTION_STRING_NAME = "OpenVision";

        public OpenVisionContext() : base(CONNECTION_STRING_NAME)
        {
        }

        public OpenVisionContext(string connectionString) : base(connectionString)
        {
        }

        public DbSet<User> Users { get; set; }

        public DbSet<Collar> Collars { get; set; }

        public DbSet<Change> Changes { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new UserMappings());
            modelBuilder.Configurations.Add(new CollarMappings());
            modelBuilder.Configurations.Add(new ChangeMappings());
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            base.OnModelCreating(modelBuilder);
        }
    }
}